package com.colorful.insuranceproject.base;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import com.colorful.insuranceproject.R;


/**
 * Created by lovely3x on 17/2/8.
 *  弹窗基类
 */
public abstract class CommonDialogFragment extends DialogFragment {

    protected View mRootView;
    protected Dialog mDialog;

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        Bundle args = getArguments();
        initArguments(args);

        mDialog = new Dialog(getContext(), R.style.transparentDialog);
        final int src = getContentView();
        mDialog.setContentView(src);

        Window window = mDialog.getWindow();

        ViewGroup decorView = (ViewGroup) window.getDecorView();

        mRootView = decorView.getChildAt(0);

        initViews();

        setupWindowAttrs(window);

        onViewInitialized();

        return mDialog;
    }


    protected void initArguments(@Nullable Bundle args){

    }

    protected abstract int getContentView();

    /**
     * 初始化视图
     */
    protected abstract void initViews();


    /**
     * 当时视图初始化完成后调用
     */
    protected abstract void onViewInitialized();


    protected void setupWindowAttrs(Window window){

    }
}
